/*! \file HXDirector.h
    \brief Head X internal message handler.

	Head X | Flinders University | Martin Luerssen & Trent Lewis | 2009+
*/

#pragma once

class HXDirector;

#include "HXPlayer.h"
#include "HXUtil.h"

//-----------------------------------------------------------------------------

class HXDirector 
{
public:
	HXDirector();
	~HXDirector();
	HXDisplay* GetDisplay() { return &m_3Display; }

	bool	Run();
	bool	IsRunning() { return m_hThread != 0; }
	void	Stop();

	void	WaitExecute(const wchar_t* command);
	void	AsyncExecute(const wchar_t* command);
	void	AsyncExecuteP(const wchar_t* text, ...);
	size_t	QueueSize() { return m_commandList.size(); }

	int		GetFrameTime() { return m_frameTime; }
	void	SetFrameTime(int milliseconds) { m_frameTime = milliseconds; }
	long	GetFramesRendered() { return m_framesRendered; }

	// Display wrapper methods
	void	SetOGLSize(int cx, int cy);
	void	Rotate(float x, float y, float z);
	void	Scale(float x, float y, float z);
	void	Translate(float x, float y, float z);
	void	ResetRotation() ;
	void	ResetScale();
	void	ResetTranslation();
	void	RotateLight(size_t lightId, float azimuth, float elevation);
	void	LightIntensity(size_t lightId, float ambient, float diffuse);
	void	ResetLights(bool loadFromConfig = false);
	void	MoveSubtitlePosition(float x, float y, float z);
	void	ResetSubtitlePosition();

	void	PlayMorph(const wstring& label, float duration, float intensity);
	void	SwitchDisplay(bool bLayered);

protected:
	void	SyncExecute(const wchar_t* command);
	void	DelayExecute(const wchar_t* command);
	static DWORD WINAPI RunDirectorThread(LPVOID lpParam);
	DWORD WINAPI DirectorThread();

	bool	ConfigOpen(wstring& argument, bool isFilename);
	bool	ParamOpen(wstring& argument, bool isFilename);
	void	ConfigClear();
	bool	BackgroundOpen(wstring& filePath);
	void	BackgroundClear();
	bool	ModelAdd(wstring& argument, bool isFilename);
	void	ModelClear();
	void	ModelRemove(wstring& argument);
	bool	ModelExport(wstring& filePath);

	int m_frameTime;
	long m_framesRendered;
	list<wstring> m_commandList;
	HANDLE m_hThread;
	bool m_bThreadExit;
	HXStopWatch m_threadClock;
	CRITICAL_SECTION	m_criticalSection_Director;

	HXDisplay m_3Display;
};

//=============================================================================

extern HXDirector g_director;
